import produce from "immer";
const initState={
    size:localStorage.getItem('size') || 'middle',
    lang: localStorage.getItem("lang") || navigator.language.split("-")[0],
    color:localStorage.getItem('color') || "#40a9ff"
}
//reducer,当成 一个子store
export  default (state=initState,{type,payload})=>{
    //1)对state进行深copy
    //2)根据action中的type和payload对状态进行操作
    //3）返回修改后的新状态
    return produce(state,newState=>{
        //CRUD
        switch(type){
            case "APP_SIZE":
                newState.size = payload
                localStorage.setItem('size',payload)
                break;
            case "APP_LANG":
                newState.lang = payload
                localStorage.setItem('lang',payload)
                break;
            case "APP_COLOR":
                newState.color = payload
                localStorage.setItem('color',payload)
                break;
        }
    })

    
}